<template>
  <div class="icons">
    <van-swipe indicator-color="blue" class="swiper-container">
      <van-swipe-item v-for="(page,index) in pages" :key="index">
        <div class="icon" v-for="item in page" :key="item.id">
          <img :src="item.iconUrl" alt>
          <p>{{item.text}}</p>
        </div>
      </van-swipe-item>
    </van-swipe>
  </div>
</template>
<script>
export default {
  data () {
    return {
      'iconList': [{
        'id': '1',
        'iconUrl': 'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
        'text': '景点门票'
      },
      {
        'id': '2',
        'iconUrl': 'http://img1.qunarzz.com/piao/fusion/1804/ff/fdf170ee89594b02.png',
        'text': '广州必游'
      },
      {
        'id': '3',
        'iconUrl': 'http://img1.qunarzz.com/piao/fusion/1803/76/eb88861d78fb9902.png',
        'text': '动植物园'
      },
      {
        'id': '4',
        'iconUrl': 'http://img1.qunarzz.com/piao/fusion/1803/95/8246f27355943202.png',
        'text': '游乐场'
      },
      {
        'id': '5',
        'iconUrl': 'http://img1.qunarzz.com/piao/fusion/1803/3e/86314b2af03b7502.png',
        'text': '珠江夜游'
      },
      {
        'id': '6',
        'iconUrl': 'http://img1.qunarzz.com/piao/fusion/1803/ab/6f7d6e44963c9302.png',
        'text': '泡温泉'
      },
      {
        'id': '7',
        'iconUrl': 'http://img1.qunarzz.com/piao/fusion/1804/5a/13ceb38dcf262f02.png',
        'text': '一日游'
      },
      {
        'id': '8',
        'iconUrl': 'http://img1.qunarzz.com/piao/fusion/1803/fa/2548667cb6e902.png',
        'text': '展馆展览'
      },
      {
        'id': '9',
        'iconUrl': 'http://img1.qunarzz.com/piao/fusion/1803/b1/528a9e80403b8c02.png',
        'text': '玩转长隆'
      },
      {
        'id': '10',
        'iconUrl': 'http://img1.qunarzz.com/piao/fusion/1803/ab/6f7d6e44963c9302.png',
        'text': '泡温泉'
      }
      ]
    }
  },
  computed: {
    pages () {
      const pages = []
      this.iconList.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        } else {
          pages[page].push(item)
        }
      })
      return pages
    }
  }
}
</script>
<style lang="scss" scoped>
.icons/deep/ .swiper-container {
  padding-bottom: 0.4rem;
}
.icons {
  background: #fff;
  width: 100%;
  .icon {
    padding-top: 0.1rem;
    float: left;
    width: 25%;
    text-align: center;
    img {
      width: 1.1rem;
    }
    p {
      padding-top: 0.1rem;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
  }
}
</style>
